package com.example.a2032.activity;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.example.a2032.R;
import com.example.a2032.Utils.SharedPreferenceUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class TimeModeActivity extends BaseActivity {

    @BindView(R.id.iv_title)
    ImageView ivTitle;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.iv_bg_mode)
    ImageView ivBgMode;
    @BindView(R.id.RadioButton_12)
    RadioButton RadioButton12;
    @BindView(R.id.RadioButton_24)
    RadioButton RadioButton24;
    @BindView(R.id.radioGroup_time)
    RadioGroup radioGroupTime;
    @BindView(R.id.tv_timeMode)
    TextView tvTimeMode;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_time_mode);
        ButterKnife.bind(this);
        init();
    }

    private void init() {
        String title = getIntent().getStringExtra(SettingActivity.KEY_SettingTitle);
        tvTitle.setText(title);
        radioGroupTime.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                boolean is24=checkedId==R.id.RadioButton_24;
                SharedPreferenceUtils.setSpBoolean(SharedPreferenceUtils.KEY_TimeMode,is24);
                changeTimeMode(is24);
            }
        });
        boolean is24= SharedPreferenceUtils.getBoolean(SharedPreferenceUtils.KEY_TimeMode,false);
        radioGroupTime.check(is24?R.id.RadioButton_24:R.id.RadioButton_12);
    }
    private void changeTimeMode(boolean is24){
        tvTimeMode.setText(is24?getString(R.string._24h):getString(R.string._12h));
    }
    @OnClick(R.id.iv_title)
    public void onViewClicked() {
        finish();
    }
}